package com.lemon.smartsafetynew.ui.adapter.task;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafetynew.entity.task.InspectionDetailVo;
import com.lemon.smartsafetynew.util.common.CommonUtil;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;

import java.util.List;

/**
 * Created by JiangAn on 2018/5/9.
 */

public class ContentAdapter extends TagAdapter<InspectionDetailVo.CheckItemsMapBean> {
    private List<InspectionDetailVo.CheckItemsMapBean> datas;
    private Context context;
    private LayoutInflater inflater;
    private Boolean isShow;

    public ContentAdapter(List<InspectionDetailVo.CheckItemsMapBean> datas, Context context) {
        super(datas);
        this.datas = datas;
        inflater = LayoutInflater.from(context);
    }

    public void setDisable(boolean isShow) {
        this.isShow = isShow;
    }

    @Override
    public View getView(FlowLayout parent, final int position, final InspectionDetailVo.CheckItemsMapBean mapBean) {
        View view = inflater.inflate(R.layout.item_inspection_status, parent, false);
        TextView tvStatusName = (TextView) view.findViewById(R.id.tv_status_name);
        ImageView ivStatus = (ImageView) view.findViewById(R.id.iv_status);
        FrameLayout flStatus = (FrameLayout) view.findViewById(R.id.fl_status);
        tvStatusName.setText(CommonUtil.avoidNullString(mapBean.getTitle()));
        if(isShow &&  !"1".equals(CommonUtil.avoidNullString(mapBean.getIsDelete()))) {
            tvStatusName.setEnabled(true);
        }else{
            tvStatusName.setEnabled(false);
        }
        if (TextUtils.isEmpty(mapBean.getStatus())) {
            ivStatus.setVisibility(View.GONE);
        }else if(mapBean.getStatus().equals("1")){
            ivStatus.setVisibility(View.VISIBLE);
            ivStatus.setImageResource(R.mipmap.format);
        }else if(mapBean.getStatus().equals("2")){
            ivStatus.setVisibility(View.VISIBLE);
            ivStatus.setImageResource(R.mipmap.noformat);
        }
        return view;
    }
}

